package com.evl.utils;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.stereotype.Service;

/**
 * bean工具类，手动获取bean对象
 * @author Think
 *
 */
@Service
public class BeanUtils implements BeanFactoryAware {

	private static BeanFactory beanFactory;
	
    @Override
    public void setBeanFactory(BeanFactory factory) throws BeansException {
    	if(beanFactory == null){
    		beanFactory=factory;
    	}else{
    		beanFactory =null;
    		beanFactory=factory;
    	}
    }
    
    public static<T> T getBean(String beanName){
           return (T) beanFactory.getBean(beanName);
    }
    
}
